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

Bunch of typing issues #389

Closed
hynek opened this Issue Jun 5, 2018 · 12 comments

Comments

Projects
None yet
3 participants
@hynek
Copy link
Member

hynek commented Jun 5, 2018

So this is mostly a meta ticket in which I ask @chadrik and @euresti (others of course too :)) for help to tell me where to direct them:

  • partials don’t work as factories: error: No overload variant of "Factory" matches argument types [functools.partial[Any]]
  • classes don’t work as converters which is a bummer because I love using yarl.URL as converter. :)
  • Having an attribute with a default and init=False makes it impossible to add more attributes. Like this:
import attr

@attr.s
class C:
   x = attr.ib(init=False, default=42)
   y = attr.ib()

It works perfectly fine to run but mypy will complain: error: Non-default attributes not allowed after default attributes.

Minor:

  • lambdas don't work as converters on purpose I suppose?
@euresti

This comment has been minimized.

Copy link
Contributor

euresti commented Jun 5, 2018

  • partials don’t work as factories: error: No overload variant of "Factory" matches argument types [functools.partial[Any]]

Stubs issue (i.e. typeshed) Though I'm a little surprised that it doesn't already work.

  • classes don’t work as converters which is a bummer because I love using yarl.URL as converter. :)

Hmm. This one is supposed to work in the plugin. What error do you get? Which version of mypy? Can you post some code?

  • Having an attribute with a default and init=False makes it impossible to add more attributes.

Plugin issue. Not something I handle correctly.

  • lambdas don't work as converters on purpose I suppose?

Plugin issue. Not so much on purpose as in they are fairly difficult to implement in mypy.

Feel free to file mypy bugs for the plugin issues, and typeshed bugs for the Factory issue.

@hynek

This comment has been minimized.

Copy link
Member Author

hynek commented Jun 5, 2018

import attr
import yarl

@attr.s
class C:
    url = attr.ib(converter=yarl.URL)

gives me: error: Unsupported converter function, only named functions are currently supported on mypy 0.600.

@euresti

This comment has been minimized.

Copy link
Contributor

euresti commented Jun 5, 2018

@hynek

This comment has been minimized.

Copy link
Member Author

hynek commented Jun 5, 2018

yarl actually has type annotations: https://github.com/aio-libs/yarl/blob/master/yarl/__init__.pyi#L6

It was the first pkg I ran into that shipped them. :)

@hynek

This comment has been minimized.

Copy link
Member Author

hynek commented Jun 5, 2018

(I tried an attrs class and the result was the same. Given the error message, it doesn’t look like it even looks at the types.)

@euresti

This comment has been minimized.

Copy link
Contributor

euresti commented Jun 5, 2018

@hynek

This comment has been minimized.

Copy link
Member Author

hynek commented Jun 5, 2018

Cool! Will enums work too? Just ran into it and it’s super useful. :)

@euresti

This comment has been minimized.

Copy link
Contributor

euresti commented Jun 5, 2018

@hynek

This comment has been minimized.

Copy link
Member Author

hynek commented Jun 5, 2018

So it’s basically just the partial thing. We should try to close #238 ASAP because right now I’m not sure where to report.

@wsanchez wsanchez added the Bug label Jun 15, 2018

@hynek

This comment has been minimized.

Copy link
Member Author

hynek commented Jul 14, 2018

  • mypy 0.620 has fixed the init=False thing.
  • it looks like
from functools import partial
import attr

f = partial(int, 42)

@attr.s
class C:
   x = attr.ib(factory=f)

works too now…I didn’t see anything in changelogs, but it doesn’t just work by accident, does it?

@euresti

This comment has been minimized.

Copy link
Contributor

euresti commented Jul 14, 2018

init=False fixed here: python/mypy#5154

git bisect tells me the other one was fixed by this python/mypy#5084
Something with how overloads are handled.

lambdas still won't work as converters though.

@hynek

This comment has been minimized.

Copy link
Member Author

hynek commented Jul 14, 2018

Coolio!

@hynek hynek closed this Jul 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.