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

Type-casting methods should return the exact type #367

Closed
senese opened this issue Nov 13, 2024 · 2 comments · Fixed by #371
Closed

Type-casting methods should return the exact type #367

senese opened this issue Nov 13, 2024 · 2 comments · Fixed by #371

Comments

@senese
Copy link
Contributor

senese commented Nov 13, 2024

Using environs I noticed that type-casting methods they don't return the type casted, only Unknown,

image

If the intention is to cast the environment variable to the correct type it should let your IDE know that it is indeed that type being returned. Environs should leverage marshmallow to return the exact type that is being casted. Type checkers like mypy would benefit from this behavior as well.

One more thing is that type-casting methods are not exactly methods and are being treated as variables although the syntax used is like calling functions. Maybe this should be reviewed in the next version?

@sloria
Copy link
Owner

sloria commented Nov 14, 2024

I agree that this would be a nice improvement. Would certainly appreciate a PR (even if just a POC) for this

OkeyDev added a commit to OkeyDev/environs that referenced this issue Nov 24, 2024
OkeyDev added a commit to OkeyDev/environs that referenced this issue Nov 24, 2024
sloria added a commit that referenced this issue Jan 7, 2025
* Added type hints for methods

Fix #367

* Build docs with py313

* Modernize type hints

* Fix typing

* Fix type hints

* Add mypy test cases

* Move types to environs.types

* Rename types

* Rename mypy test file so it doesn't get run my pytest

* DRY common kwargs

* Add __future__ import to fix py39

* Update changelog

* Add back subcast_keys and subcast_values

* Add case for untyped parser

---------

Co-authored-by: Steven Loria <[email protected]>
@sloria
Copy link
Owner

sloria commented Jan 7, 2025

This is released in 13.0.0 🙌

CleanShot 2025-01-07 at 16 52 48@2x

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

Successfully merging a pull request may close this issue.

2 participants