Repository: cython/cython

Issue:
[BUG] "Python global or builtin not a Python object" error when cythonizing a float annotation
**Describe the bug**
Cythonizing the code below results in the following error:
```py
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "<elided>\Scripts\cython.exe\__main__.py", line 7, in <module>
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 714, in setuptools_main
    return main(command_line = 1)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 732, in main
    result = compile(sources, options)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 630, in compile
    return compile_multiple(source, options)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 607, in compile_multiple
    result = run_pipeline(source, options, context=context)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 505, in run_pipeline
    err, enddata = Pipeline.run_pipeline(pipeline, source)
  File "<elided>\lib\site-packages\Cython\Compiler\Pipeline.py", line 371, in run_pipeline
    data = run(phase, data)
  File "<elided>\lib\site-packages\Cython\Compiler\Pipeline.py", line 351, in run
    return phase(data)
  File "<elided>\lib\site-packages\Cython\Compiler\Pipeline.py", line 52, in generate_pyx_code_stage
    module_node.process_implementation(options, result)
  File "<elided>\lib\site-packages\Cython\Compiler\ModuleNode.py", line 171, in process_implementation
    self.generate_c_code(env, options, result)
  File "<elided>\lib\site-packages\Cython\Compiler\ModuleNode.py", line 483, in generate_c_code
    self.generate_module_init_func(modules[:-1], env, globalstate['init_module'])
  File "<elided>\lib\site-packages\Cython\Compiler\ModuleNode.py", line 2940, in generate_module_init_func
    self.body.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 409, in generate_execution_code
    stat.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 4975, in generate_execution_code
    self.body.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 409, in generate_execution_code
    stat.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 5642, in generate_execution_code
    self.generate_assignment_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 5939, in generate_assignment_code
    self.lhs.generate_assignment_code(self.rhs, code)
  File "<elided>\lib\site-packages\Cython\Compiler\ExprNodes.py", line 2366, in generate_assignment_code
    assert entry.type.is_pyobject, "Python global or builtin not a Python object"
AssertionError: Python global or builtin not a Python object
```

**To Reproduce**
Code to reproduce the behaviour:
```cython
# cython: language_level=3

class Foo:
    bar: float = 0.1
```

**Expected behavior**
It cythonizes without an error.

**Environment:**
 - OS: Windows 10
 - Python version: 3.8.7
 - Cython version: 3.0a7

**Additional context**
The error does not occur when:
 - Using a string annotation (`bar: "float" = 0.1`)
 - A different type is used (`bar: int = 1`)
 - No value is given (`bar: float`)



Discussion:

Resolving patch:
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -1996,6 +1996,9 @@ def declare_from_annotation(self, env, as_target=False):
                 or not env.directives['annotation_typing']
             ):
                 atype = None
+            elif env.is_py_class_scope:
+                # For Python class scopes every attribute is a Python object
+                atype = py_object_type
             else:
                 _, atype = annotation.analyse_type_annotation(env)
             if atype is None:


Test patch:
diff --git a/tests/run/pep526_variable_annotations.py b/tests/run/pep526_variable_annotations.py
--- a/tests/run/pep526_variable_annotations.py
+++ b/tests/run/pep526_variable_annotations.py
@@ -165,7 +165,6 @@ def literal_list_ptr():
 37:19: Unknown type declaration in annotation, ignoring
 38:12: Unknown type declaration in annotation, ignoring
 39:18: Unknown type declaration in annotation, ignoring
-57:19: Unknown type declaration in annotation, ignoring
 73:11: Annotation ignored since class-level attributes must be Python objects. Were you trying to set up an instance attribute?
 73:19: Unknown type declaration in annotation, ignoring
 # FIXME: these are sort-of evaluated now, so the warning is misleading
diff --git a/tests/run/pyclass_annotations_pep526.py b/tests/run/pyclass_annotations_pep526.py
--- a/tests/run/pyclass_annotations_pep526.py
+++ b/tests/run/pyclass_annotations_pep526.py
@@ -11,6 +11,8 @@
 except ImportError:  # Py<=3.5
     ClassVar = {int: int}
 
+class NotAStr:
+    pass
 
 class PyAnnotatedClass:
     """
@@ -38,6 +40,9 @@ class PyAnnotatedClass:
     literal: "int"
     recurse: "PyAnnotatedClass"
     default: bool = False
+    # https://github.com/cython/cython/issues/4196 and https://github.com/cython/cython/issues/4198
+    not_object: float = 0.1  # Shouldn't try to create a c attribute
+    lie_about_type: str = NotAStr  # Shouldn't generate a runtime type-check
 
 
 class PyVanillaClass: