Your second way is correct.

def foo(opts: dict = {}):
    pass

print(foo.__annotations__)

this outputs

{'opts': <class 'dict'>}

Although it is not explicitly mentioned in PEP 484, type hints are a specific use of function annotations, as outlined in PEP 3107. The syntax section clearly demonstrates that keyword arguments can be annotated in this manner.

I strongly advise against using mutable keyword arguments. More information here.

Answer from noɥʇʎԀʎzɐɹƆ on Stack Overflow
🌐
LabEx
labex.io › tutorials › python-how-to-specify-default-parameter-types-438410
How to specify default parameter types | LabEx
When a function is called without providing a specific value for a parameter, the default value is used instead. def greet(name="Guest"): print(f"Hello, {name}!") ## Calling the function with and without an argument greet() ## Output: Hello, ...
Discussions

python - Set default value and type for parameter - Stack Overflow
In short, you can't guarantee types in python. When you set the default value of pk=0, you make its default value an int, but someone using your function could easily call More on stackoverflow.com
🌐 stackoverflow.com
A way to have the default value for a parameter as the default of another function: the Default singleton - Ideas - Discussions on Python.org
Often, I use the defaults of another function in my new function or class. For example: def mysorted(it, key=None, reversed=False): # some code return sorted(it, key=key, reversed=reversed) The majority of times I want to simply adhere to the sign of the original function. More on discuss.python.org
🌐 discuss.python.org
1
September 7, 2022
Can I define both function's argument's default value and data type in python? - Stack Overflow
I want to write something like this. def func_name(arg1, arg2, arg3 = 3) #this defines default value for optional argument arg3 def func_name(arg1, arg2, arg3: int) #and this defines data type for More on stackoverflow.com
🌐 stackoverflow.com
Today I re-learned: Python function default arguments are retained between executions
I had to find this out the hard way :/ P.s. I am a little rusty on python, but if you want a mutable default value (say a list) you can make the default None then inside the function you would reassign the variable if it's None. More on reddit.com
🌐 r/Python
170
391
January 20, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › default-arguments-in-python
Default arguments in Python - GeeksforGeeks
In the first call greet(), no argument is passed, so Python uses the default value "Guest". In the second call greet("Kate"), the default value is overridden with "Kate". def function_name(param1=value1, param2=value2, ...): # function body ...
Published: March 18, 2026
🌐
Boot.dev
boot.dev › lessons › 3963019a-a8ce-45c0-b988-3e6e4121aa36
Learn Python for Beginners: Default Values | Boot.dev
They both take two integers as arguments, health and armor. ... In the function signature, give the armor parameter a default value of 0.
🌐
W3Schools
w3schools.com › python › gloss_python_function_default_parameter.asp
Python Default Parameter Value
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The following example shows how to use a default parameter value. If we call the function without argument, it uses the default value:
🌐
Python Tutorial
pythontutorial.net › home › python basics › python default parameters
Python Default Parameters
October 5, 2020 - To specify default values for parameters, you use the following syntax: def function_name(param1, param2=value2, param3=value3, ...):Copy · In this syntax, you specify default values (value2, value3, …) for each parameter using the assignment operator (=). When you call a function and pass ...
Find elsewhere
🌐
Python.org
discuss.python.org › ideas
A way to have the default value for a parameter as the default of another function: the Default singleton - Ideas - Discussions on Python.org
September 7, 2022 - Often, I use the defaults of another function in my new function or class. For example: def mysorted(it, key=None, reversed=False): # some code return sorted(it, key=key, reversed=reversed) The majority of time…
🌐
EITCA
eitca.org › home › what are default values for function parameters and how can they be specified?
What are default values for function parameters and how can they be specified? - EITCA Academy
August 3, 2023 - This feature provides flexibility and allows us to define functions that can be called with different sets of arguments. In Python, default values for function parameters are specified in the function definition using the assignment operator (=).
🌐
Python documentation
docs.python.org › 3 › library › typing.html
typing — Support for type hints
1 week ago - At runtime, P.args and P.kwargs are instances respectively of ParamSpecArgs and ParamSpecKwargs. ... The name of the parameter specification. ... The default value of the parameter specification, or typing.NoDefault if it has no default. Added in version 3.13. ... An evaluate function corresponding to the __default__ attribute.
🌐
Codingem
codingem.com › home › python default arguments: a complete guide (with examples)
Python Default Arguments: A Complete Guide (with Examples)
November 5, 2022 - And if the input value is provided, that’s going to be used in the function. You can add default function parameters in Python by giving a default value for a parameter in the function definition using the assignment operator (=).
🌐
Programiz
programiz.com › python-programming › function-argument
Python Function Arguments (With Examples)
No value is passed during the function call. Hence, default value is used for both parameters a and b.
🌐
Reddit
reddit.com › r/python › today i re-learned: python function default arguments are retained between executions
r/Python on Reddit: Today I re-learned: Python function default arguments are retained between executions
January 20, 2023 - No. strings are immutables in python. It's perfectly safe to write ... “stick to literals” is not good advice. List and dictionary literals would be problematic as default parameter values since those are mutable types. Ironically the example you’ve given here could be simplified by just using the string literal as the default since strings are immutable.
🌐
Reddit
reddit.com › r/learnpython › type hinting weirdness with "none" as default value when i need to default to class' initial value or get a value from user
r/learnpython on Reddit: Type hinting weirdness with "None" as default value when I need to default to class' initial value or get a value from user
March 29, 2023 -

Sorry for the confusing title.

I have been adding some type hinting into my code and noticed that if I have something like:

def create(self, a: int = None) -> None
a = a or self.a

Where I would like to have the user either give a as an int or just skip it and the function will default to the class' initial value for a. This works just fine but this shows in the IDE as create(self, a: int | None = None) -> None which looks like None is a valid value for a, even though that is not what I am looking for.

Then if I have an artificial case like:

def create(self, a: int = 'test') -> None
...

Which then shows up as create(self, a: int = 'test') -> None which looks weird but at least it doesn't explicitly imply that str is a valid parameter.

So I guess two questions: what makes None special? And, is this the way to use type hinting when I need to default to class' initial value or get an argument from user?

🌐
Codecademy
codecademy.com › learn › learn-intermediate-python-3 › modules › int-python-function-arguments › cheatsheet
Learn Intermediate Python 3: Function Arguments Cheatsheet | Codecademy
In Python, a default parameter is defined with a fallback value as a default argument. Such parameters are optional during a function call. If no argument is provided, the default value is used, and if an argument is provided, it will overwrite ...
🌐
Python
peps.python.org › pep-0696
PEP 696 – Type Defaults for Type Parameters | peps.python.org
This allows for a value to be used again when the type parameter to a generic is missing but another type parameter is specified. To use another type parameter as a default the default and the type parameter must be the same type (a TypeVar’s ...
🌐
Real Python
realpython.com › python-optional-arguments
Using Python Optional Arguments When Defining Functions – Real Python
July 19, 2026 - By the end of this tutorial, you’ll understand that: Parameters are names in a function definition, while arguments are the values you pass when calling the function · You can assign default values to parameters so that arguments become optional ...
🌐
GUVI
guvi.in › hub › python › default-parameters-in-python
Default Parameters in Python
Default parameters in Python allow you to assign default values to function parameters. Default parameters are used when a value is not provided for a particular parameter during function invocation.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Default Parameter Values in Python Functions | note.nkmk.me
May 12, 2025 - # def func_default_error(arg2='default_a', arg3='default_b', arg1): # print(arg1) # print(arg2) # SyntaxError: parameter without a default follows parameter with a default ... Mutable default values like lists or dictionaries are created when the function is defined and reused in subsequent calls if the corresponding argument is omitted.