Repository: django/django
File: tests/utils_tests/test_inspect.py (Python)

Code before:
        self.assertIs(inspect.method_has_no_args(Person.no_arguments), True)
        self.assertIs(inspect.method_has_no_args(Person().no_arguments), True)
        self.assertIs(inspect.method_has_no_args(Person.one_argument), False)
        self.assertIs(inspect.method_has_no_args(Person().one_argument), False)

    def test_func_supports_parameter(self):
        self.assertIs(
            inspect.func_supports_parameter(Person.all_kinds, "address"), True
        )
        self.assertIs(
            inspect.func_supports_parameter(Person().all_kinds, "address"),
            True,
        )
        self.assertIs(inspect.func_supports_parameter(Person.all_kinds, "zone"), False)
        self.assertIs(
            inspect.func_supports_parameter(Person().all_kinds, "zone"),
            False,
        )

    def test_func_accepts_kwargs(self):
        self.assertIs(inspect.func_accepts_kwargs(Person.just_args), False)
        self.assertIs(inspect.func_accepts_kwargs(Person().just_args), False)
        self.assertIs(inspect.func_accepts_kwargs(Person.all_kinds), True)
        self.assertIs(inspect.func_accepts_kwargs(Person().just_args), False)

    @unittest.skipUnless(PY314, "deferred annotations are python 3.14+ only")
    def test_func_accepts_kwargs_deferred_annotations(self):

        def func_with_annotations(self, name: str, complex: SafeString) -> None:
            pass

        # Inspection fails with deferred annotations with python 3.14+. Earlier
        # Python versions trigger the NameError on module initialization.
        self.assertIs(inspect.func_accepts_kwargs(func_with_annotations), False)


class IsModuleLevelFunctionTestCase(unittest.TestCase):
    @classmethod
    def _class_method(cls) -> None:
        return None

    @staticmethod
    def _static_method() -> None:
        return None

    def test_builtin(self):
        self.assertIs(inspect.is_module_level_function(any), False)
        self.assertIs(inspect.is_module_level_function(isinstance), False)

    def test_from_module(self):
        self.assertIs(inspect.is_module_level_function(subprocess.run), True)

Review comment (suggestion):
```suggestion
    @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only")
```

Code after:
        self.assertIs(inspect.method_has_no_args(Person.no_arguments), True)
        self.assertIs(inspect.method_has_no_args(Person().no_arguments), True)
        self.assertIs(inspect.method_has_no_args(Person.one_argument), False)
        self.assertIs(inspect.method_has_no_args(Person().one_argument), False)

    def test_func_supports_parameter(self):
        self.assertIs(
            inspect.func_supports_parameter(Person.all_kinds, "address"), True
        )
        self.assertIs(
            inspect.func_supports_parameter(Person().all_kinds, "address"),
            True,
        )
        self.assertIs(inspect.func_supports_parameter(Person.all_kinds, "zone"), False)
        self.assertIs(
            inspect.func_supports_parameter(Person().all_kinds, "zone"),
            False,
        )

    def test_func_accepts_kwargs(self):
        self.assertIs(inspect.func_accepts_kwargs(Person.just_args), False)
        self.assertIs(inspect.func_accepts_kwargs(Person().just_args), False)
        self.assertIs(inspect.func_accepts_kwargs(Person.all_kinds), True)
        self.assertIs(inspect.func_accepts_kwargs(Person().just_args), False)

    @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only")
    def test_func_accepts_kwargs_deferred_annotations(self):

        def func_with_annotations(self, name: str, complex: SafeString) -> None:
            pass

        # Inspection fails with deferred annotations with python 3.14+. Earlier
        # Python versions trigger the NameError on module initialization.
        self.assertIs(inspect.func_accepts_kwargs(func_with_annotations), False)


class IsModuleLevelFunctionTestCase(unittest.TestCase):
    @classmethod
    def _class_method(cls) -> None:
        return None

    @staticmethod
    def _static_method() -> None:
        return None

    def test_builtin(self):
        self.assertIs(inspect.is_module_level_function(any), False)
        self.assertIs(inspect.is_module_level_function(isinstance), False)

    def test_from_module(self):
        self.assertIs(inspect.is_module_level_function(subprocess.run), True)