Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling vtype at top level fails #3

Open
piccolbo opened this issue Jun 13, 2022 · 1 comment
Open

Calling vtype at top level fails #3

piccolbo opened this issue Jun 13, 2022 · 1 comment

Comments

@piccolbo
Copy link

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!

@smarie
Copy link
Owner

smarie commented Jun 14, 2022

Wow so sorry for this @piccolbo !

Unfortunately currently this project still has an old layout (that is using travis ci and does not include nox) so not sure how easy it would be for you to propose a PR if you would like to.

Alternately, I'll have to spend some time migrating the layout to the new format (same as for example https://github.com/smarie/python-makefun). Not sure when I'll be able to do this, probably during summer

Since I had already looked into your other work, that was not going to stop me!

thanks for the kind words ! I appreciate :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants