Fokko commented on code in PR #4920: URL: https://github.com/apache/iceberg/pull/4920#discussion_r895419347
########## python/src/iceberg/utils/singleton.py: ########## @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from abc import ABCMeta +from typing import Dict + + +class Singleton(type, metaclass=ABCMeta): Review Comment: Hey Ryan, since you've merged https://github.com/apache/iceberg/pull/5008 we can re-use that singleton. I'll update the code. I've also added a docstring for the singleton module to elaborate why we need it: ``` This is a singleton metaclass that can be used to cache and re-use existing objects In the Icebeg codebase we have a lot of objects that are stateless (for example Types such as StringType, BooleanType etc). FixedTypes have arguments (eg. Fixed[22]) that we also make part of the key when caching the newly created object. The Singleton uses a metaclass which essentially defines a new type. When the Type gets created, it will first evaluate the `__call__` method with all the arguments. If we already initialized a class earlier, we'll just return it. More information on metaclasses: https://docs.python.org/3/reference/datamodel.html#metaclasses ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
