Skip to content

Calling vtype at top level fails #3

@piccolbo

Description

@piccolbo

Hi this is just an inconvenience I am reporting but it may discourage some people just checking out your package. When I first found about it i just typed this into an ipython session

from vtypes import vtype
PositiveInt = vtype("PositiveInt", int, {"should be positive": lambda x: x >= 0})

and got

In [7]: PositiveInt = vtype("PositiveInt", int, {"should be positive": lambda x: x >= 0})
   ...: 
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 PositiveInt = vtype("PositiveInt", int, {"should be positive": lambda x: x >= 0})

File /usr/local/lib/python3.10/site-packages/vtypes/core.py:400, in vtype(name, base, validators, help_msg, error_type, doc)
    386 """
    387 Creates a new Validating Type, a subclass of VType.
    388 
   (...)
    396 :return:
    397 """
    398 new_type = VTypeMeta(name, (VType,), dict(__type__=base, __validators__=validators,
    399                                           __help_msg__=help_msg, __error_type__=error_type))
--> 400 new_type.__module__ = get_caller_module().__name__
    401 if doc is not None:
    402     new_type.__doc__ = doc

AttributeError: 'NoneType' object has no attribute '__name__'

It works just fine running from a file with %run, because, I suppose, then the caller module is that file, but not with %load, because that's equivalent to typing it in, and apparently it was too hard for the Python folks to call that a stdin or console module or what have you.

So this is not a problem developing with your package, but when you try out things and the first thing you do you break them, it may be discouraging. Since I had already looked into your other work, that was not going to stop me!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions