You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Class based actions: Mypy not happy with defined parameters in the run method #457
Thanks for the report! So this is an inherent mypy limitation/conscious decisiom. Mypy has no way of knowing that the fields are dynamically set by the inputs() property. To work aroudn it, you would want to use **kwargs as the signature and access the parameters dynamically. E.G.
defrun(self,
state: State,
**kwargs) ->dict:
# can access the app_id from the __context__context=kwargs["context"]
increment_by=kwargs["increment_by"]
print(__context.app_id, __context.partition_key, __context.sequence_id)
return {"counter": state["counter"] +increment_by}
We chose not to have that as it's harder to read, and I'm less a believer in strict type-checking in python, but it's there if you want it! You may be able to do something with a typed dict/type-hinting kwargs as well -- haven't tested it out -- see https://peps.python.org/pep-0692/
Thanks for the response. For now have considered the options, I probably will just put type: ignore[override] to each individual occassion of overriding the run method in a class based action. Being a strong believer of type checking in Python myself this is quite a lot of frictions.
Thanks for the response. For now have considered the options, I probably will just put type: ignore[override] to each individual occassion of overriding the run method in a class based action. Being a strong believer of type checking in Python myself this is quite a lot of frictions.
Hey! Glad you found a workaround. Sorry for the delay in responding! TBH I think this is an area in which mypy could improve, and also an area in which python/strict type-checking falls a bit flat. That said, I wouldn't be surprised if there's a better way to define the superclass, and I'm happy to dig in a bit. It quite annoys me as well... Will report back!
Happy to consider adding adapt_types to the framework itself (we'd use it internally), and thinking about how to ensure it doesn't loose too much. But it is extra code.
@elijahbenizzy@stefan-ernst@shun-liang opened #683 with a flexible_api decorator to fix this. Tested on Python 3.12 + mypy 1.19.1 in an isolated Docker environment and the override error is gone. Would appreciate a review.
Activity
elijahbenizzy commentedon Dec 5, 2024
Thanks for the report! So this is an inherent mypy limitation/conscious decisiom. Mypy has no way of knowing that the fields are dynamically set by the
inputs()property. To work aroudn it, you would want to use**kwargsas the signature and access the parameters dynamically. E.G.We chose not to have that as it's harder to read, and I'm less a believer in strict type-checking in python, but it's there if you want it! You may be able to do something with a typed dict/type-hinting kwargs as well -- haven't tested it out -- see https://peps.python.org/pep-0692/
shun-liang commentedon Dec 5, 2024
Thanks for the response. For now have considered the options, I probably will just put
type: ignore[override]to each individual occassion of overriding the run method in a class based action. Being a strong believer of type checking in Python myself this is quite a lot of frictions.elijahbenizzy commentedon Dec 10, 2024
Hey! Glad you found a workaround. Sorry for the delay in responding! TBH I think this is an area in which mypy could improve, and also an area in which python/strict type-checking falls a bit flat. That said, I wouldn't be surprised if there's a better way to define the superclass, and I'm happy to dig in a bit. It quite annoys me as well... Will report back!

elijahbenizzy commentedon Dec 10, 2024
OK, so I dug in a bit. This is not something we're going to be able to solve at a framework level but I think you have two good options:
**kwargs-- this is "safer" (you're doing the validation, not trusting the framework), but less typed/less funHappy to consider adding
adapt_typesto the framework itself (we'd use it internally), and thinking about how to ensure it doesn't loose too much. But it is extra code.This does not work, it has the same error (understandibly so) https://peps.python.org/pep-0692/.
core: add flexible_api decorator to fix mypy override errors on class…
andreahlert commentedon Mar 18, 2026
@elijahbenizzy @stefan-ernst @shun-liang opened #683 with a
flexible_apidecorator to fix this. Tested on Python 3.12 + mypy 1.19.1 in an isolated Docker environment and the override error is gone. Would appreciate a review.core: add flexible_api decorator to fix mypy override errors (#683)
andreahlert commentedon Mar 28, 2026
Labels migrated to new taxonomy (#692).