@@ -1956,16 +1956,33 @@ def test_sentinel(self):
19561956 with self .assertRaises (TypeError ):
19571957 class SubSentinel (sentinel ):
19581958 pass
1959+
1960+ def test_sentinel_attributes (self ):
1961+ missing = sentinel ("MISSING" )
19591962 with self .assertRaises (TypeError ):
19601963 sentinel .attribute = "value"
19611964 with self .assertRaises (AttributeError ):
1962- missing .__name__ = "CHANGED "
1965+ missing .attribute = "value "
19631966 with self .assertRaises (AttributeError ):
1964- missing .__module__ = "changed"
1967+ missing .__name__ = "CHANGED"
1968+ missing .__module__ = "changed"
1969+ self .assertEqual (missing .__module__ , "changed" )
19651970 with self .assertRaises (AttributeError ):
19661971 del missing .__name__
1972+ del missing .__module__
19671973 with self .assertRaises (AttributeError ):
1968- del missing .__module__
1974+ missing .__module__
1975+
1976+ def test_sentinel_repr (self ):
1977+ with_repr = sentinel ("WITH_REPR" , repr = "custom" )
1978+ without_repr = sentinel ("WITHOUT_REPR" , repr = None )
1979+ self .assertEqual (repr (with_repr ), "custom" )
1980+ self .assertEqual (repr (without_repr ), "WITHOUT_REPR" )
1981+ self .assertEqual (str (with_repr ), "custom" )
1982+ self .assertEqual (str (without_repr ), "WITHOUT_REPR" )
1983+
1984+ with self .assertRaisesRegex (TypeError , "repr.*str or None" ):
1985+ sentinel ("BAD_REPR" , repr = 42 )
19691986
19701987 def test_sentinel_pickle (self ):
19711988 for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
0 commit comments