Comments (5)
I forget the error this raises, but:
def fcn(x:None| int = None):
if x is None:
x = 0
y = x + 1
This raises a mypy error because it thinks x can still be None on the last line, and it drives me crazy since this is a pretty common design pattern!
from plasmapy.
Huh, the mypy error I get from that is no-untyped-def
since there's no return type annotation. mypy is usually good at type narrowing, assuming it can infer what's in the if
statement. I'm curious if the error you ran into is happening because there's some dynamical typing happening. 🤔 @pheuer — could you ping me the next time you run into an error like this?
I'm wondering if it may be associated with untyped decorators (like @validate_quantities
). Otherwise it's sometimes possible to define a TypeGuard
.
Thank you for bringing this up!
from plasmapy.
Ah, maybe it is related to decorators? I'll keep an eye out for next time. Here's another pytest specific one
def test_fcn(ex : Exception | None):
with pytest.raises(ex):
...
For some reason mypy is looking for an overloaded function (raising call-overload
) for pytest.raises
that has Exception
as its class, except isn't that just the default (and only?) signature for that function?
from plasmapy.
Interesting! I believe the pytest API changed recently so that pytest.raises
no longer accepts None
, but we get the call-overload
error even after removing the | None
. (The source file of pytest.raises
contains a few signatures of pytest.raises
that are decorated with @overload
.) In any case, this is a good motivation to ignore call-overload
in all test files since the advantages of having the more in-depth type hints don't outweigh the extra complicatedness of having to do all that. Thanks!
from plasmapy.
When trying to add particlewise
to particle_collections.is_category
, the static type check for mypy kept raising issues with this code:
PlasmaPy/src/plasmapy/particles/decorators.py
Lines 525 to 533 in ca92246
The "issue" is that the individual Particle
class has a method without particlewise
as a keyword, so it would only return a bool
, which is not iterable. The third condition can only be called, however, given that it passes the check for isinstance(particle, ParticleList)
, so this cannot be an issue (unless you can somehow pass that second check otherwise?).
This was frustrating trying to debug. The only way I could think was to use nested conditionals, which then ruff complains about. The solution I used was just to tell mypy to ignore it # type: ignore[arg-type]
.
I don't know if there's any more clever way.
from plasmapy.
Related Issues (20)
- `thomson_fitting` error with `lmfit==1.3.0` HOT 3
- Make it so that `plasmapy.__version__` uses current date in editable installs
- Verify that files are included or not included in source distributions and wheels
- Show correct version in title of `latest` docs
- Enable weekly tests with the JIT compiler to be added in Python 3.13
- CI codecov bug HOT 2
- Allow ParticleTracker to accept analytical fields (as functions) or lists of currents/charges
- Add helper functionality to plot quantities against temperature with axes labeled in both K and eV HOT 2
- Add `latex_str` attribute to `Particle`
- Add Jupyter notebook that plots reconnection phase diagram
- what is the unit of temperature defined in the Spitzer resistivity HOT 3
- Requirements files need to be rethought HOT 4
- Spin off plasma calculator into separate affiliated package
- Rename `binding_energy` property of `Particle` to `nuclear_binding_energy` and add `electron_binding_energy` based on `ionization_energy`
- Add a Nox session to build the changelog
- Apparent bug in ion contribution to Thomson scattering spectrum HOT 1
- Adding `__str__` to `CustomParticle`.
- Flaky Failure in `test_floating_potential` HOT 2
- Perform benchmarks of parallel documentation builds after disabling Sphinx extensions
- Bring back `ROADMAP.md` to include PlasmaPy's development roadmap
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plasmapy.